﻿using System;
using System.IO;
using System.Security.Cryptography;
using System.Net;
using System.Collections.Specialized;
using System.Web;
using OAuth;
using Darren.Common.Helper;

public partial class localback : System.Web.UI.Page
{


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //sina
            if (Request["oauth_verifier"] != null)
            {
                string oauth = CookieHelper.GetCookieValue("SinaOAuth");

                string oauth_token = StringHelper.QueryString(oauth, "Token");
                string oauth_token_secret = StringHelper.QueryString(oauth, "TokenSecret");
                string oauth_verifier = Request["oauth_verifier"];

                SinaOAuth auth = new SinaOAuth();
                auth.Token.Token = oauth_token;
                auth.Token.TokenSecret = oauth_token_secret;
                AccessToken access = auth.GetAccessToken(oauth_verifier);

                CookieHelper.SetCookie("SinaOAuth", string.Format("Token={0}&TokenSecret={1}&OpenID={2}", access.Token, access.TokenSecret, access.Openid));
                Response.Redirect(SinaOAuth.CallBackURL);
            }
            //qq
            else if (Request["oauth_vericode"] != null)
            {
                string oauth_token = Request["oauth_token"];
                string oauth_vericode = Request["oauth_vericode"];

                string oauth = CookieHelper.GetCookieValue("QQOAuth");

                string oauth_token_secret = StringHelper.QueryString(oauth, "TokenSecret");

                QQOAuth auth = new QQOAuth();
                auth.Token = new AccessToken(oauth_token, oauth_token_secret, null);
                AccessToken access = auth.GetAccessToken(oauth_vericode);

               
                CookieHelper.SetCookie("SinaOAuth", string.Format("Token={0}&TokenSecret={1}&OpenID={2}", access.Token, access.TokenSecret, access.Openid));

                Response.Redirect("QQDemo.aspx");
            }
            //163
            else
            {
                string oauth_token = Request["oauth_token"];

                string oauth = CookieHelper.GetCookieValue("NetEasyOAuth");
                string oauth_token_secret = StringHelper.QueryString(oauth, "TokenSecret");
                //string oauth_token_secret = Session["oauth_token_secret"].ToString();

                NetEasyOAuth auth = new NetEasyOAuth();
                auth.Token = new AccessToken(oauth_token, oauth_token_secret, null);
                AccessToken access = auth.GetAccessToken();

                //Session["access_oauth_token"] = access.Token;
                //Session["access_oauth_token_secret"] = access.TokenSecret;
                //Session["access_openid"] = access.Openid;

                CookieHelper.SetCookie("NetEasyOAuth", string.Format("Token={0}&TokenSecret={1}&OpenID={2}", access.Token, access.TokenSecret, access.Openid));
                Response.Redirect("NetEasyDemo.aspx");
            }
        }
        
    }
}